<?php
Junction_FileCabinet::using("Junction_Core_Mapping");
Junction_FileCabinet::using("Junction_Core_Excpetion");
Junction_FileCabinet::using("Junction_Expression_Parser");
/**
 * Mediator for the mapping class
 * 
 * <p>This class provides an interface for handling the core mapper.
 * The goal of this class is to provide a convenient and easy to use
 * interface for the client.
 * <p>This class is also responsible for constructing the WHERE 
 * clause of any given query.  This means that it must validate the
 * user submitted expression.
 *
 * @package junction.core
 */
class Junction_Core_Session
{
	/**
	 * Handle to satisfy client requests
	 *
	 * @var Junction_Core_Mapping
	 */
	private $_mapping;
	
	/**
	 * Session Constructor
	 * 
	 * @param Junction_Core_Mapping $class
	 */
	public function __construct($class) {
		$this->_mapping = $class;
	}
		
	/**
	 * Attempt to fetch a client object with the given id.
	 * 
	 * @param string $id
	 * @return Object
	 */
	public function loadById($id) {
		throw new Exception("Method not implemented");
	}
	
	/**
	 * Attempt to fetch multiple client objects which match the given expression.
	 * 
	 * @throws Junction_MalformedExpressionException
	 * @param Junction_Expression $expression
	 * @return array of objects
	 */
	public function load($expression) {
		$parser = new Junction_Expression_Parser();
		$parser->parse($expression);
		
		return $this->_mapping->fetch($expression);
	}
	
	/**
	 * Save the object's state to the database.
	 * 
	 * @param Object $object
	 * @return Object
	 */
	public function save($object) {
		return $this->_mapping->save($object);
	}
	
	/**
	 * Delete the client object from persistance.
	 *
	 * @param string $id
	 * @return boolean
	 */
	public function deleteById($id) {
		throw new Exception("Method not implemented");
	}
	
	/**
	 * Delete objects which match the given expression.
	 * 
	 * @param Junction_Expression
	 * @throws Junction_MalformedExpressionException
	 * @return int number of affected rows
	 */
	public function delete($expression) {
		return $this->_mapping->delete($expression);
	}
}
?>
